/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchdienbienhochamException;
import doan.quanlycanbo.portlet.model.dienbienhocham;
import doan.quanlycanbo.portlet.service.base.dienbienhochamLocalServiceBaseImpl;

/**
 * The implementation of the dienbienhocham local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link doan.quanlycanbo.portlet.service.dienbienhochamLocalService} interface.
 * </p>
 *
 * <p>
 * Never reference this interface directly. Always use {@link doan.quanlycanbo.portlet.service.dienbienhochamLocalServiceUtil} to access the dienbienhocham local service.
 * </p>
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Nguyen Tuan Vinh
 * @see doan.quanlycanbo.portlet.service.base.dienbienhochamLocalServiceBaseImpl
 * @see doan.quanlycanbo.portlet.service.dienbienhochamLocalServiceUtil
 */
public class dienbienhochamLocalServiceImpl
	extends dienbienhochamLocalServiceBaseImpl {
	
		public dienbienhocham getByPrimaryKey(long madbhh) throws NoSuchdienbienhochamException, SystemException{
			return dienbienhochamPersistence.findByPrimaryKey(madbhh);
		}
	
		public List<dienbienhocham> getAll() throws SystemException{
			return dienbienhochamPersistence.findAll();
		}
	
		public List<dienbienhocham> getByHoso(long mahoso) throws SystemException{
			return dienbienhochamPersistence.findByHoSo(mahoso);
		}
	
		public List<dienbienhocham> getByHocham(long mahocham) throws SystemException{
			return dienbienhochamPersistence.findByHocHam(mahocham);
		}
		
		public dienbienhocham addDBHH(dienbienhocham dbhh1, long userId) throws SystemException{
			long madbhh = CounterLocalServiceUtil.increment(dienbienhocham.class.getName());
			
			dienbienhocham dbhh2 = dienbienhochamPersistence.create(madbhh);
			dbhh2.setGroupId(dbhh1.getGroupId());
			dbhh2.setCompanyId(dbhh1.getCompanyId());
			dbhh2.setLanguageId(dbhh1.getLanguageId());
			dbhh2.setMahoso(dbhh1.getMahoso());
			dbhh2.setMahocham(dbhh1.getMahocham());
			dbhh2.setChuyennganh(dbhh1.getChuyennganh());
			dbhh2.setNamphong(dbhh1.getNamphong());
			
			try {
				resourceLocalService.addResources(dbhh1.getCompanyId(), dbhh1.getGroupId(), userId, 
						dienbienhocham.class.getName(), dbhh2.getPrimaryKey(), false, true, true);
			} catch (PortalException e) {
				e.printStackTrace();
			}
			
			return dienbienhochamPersistence.update(dbhh2, false);
		}
		
		public dienbienhocham updateDBHH(long madbhh,long maHocham, String chuyennganh, int namphong) throws NoSuchdienbienhochamException, SystemException{
			dienbienhocham dbhh = dienbienhochamPersistence.findByPrimaryKey(madbhh);
			dbhh.setMahocham(maHocham);
			dbhh.setChuyennganh(chuyennganh);
			dbhh.setNamphong(namphong);
			return dienbienhochamPersistence.update(dbhh, false);
		}
		
		public void deleteDBHH(long madbhh) throws SystemException, PortalException{
			dienbienhocham dbhh = dienbienhochamPersistence.findByPrimaryKey(madbhh);
			deleteDBHH(dbhh);
		}
		
		public void deleteDBHH(dienbienhocham dbhh) throws PortalException, SystemException{
			resourceLocalService.deleteResource(dbhh.getCompanyId(), dienbienhocham.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, dbhh.getPrimaryKey());
			dienbienhochamPersistence.remove(dbhh);
		}
		
		
		
}